Passed
Pull Request — master (#2)
by André
01:32
created

check.js ➔ ... ➔ ???   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 10
c 0
b 0
f 0
nc 1
dl 0
loc 4
rs 9.9
nop 2
1
'use strict'
2
3
module.exports = (input, callback) => {
4
	const mqtt = require('mqtt')
5
	const validate = require('./validate')
6
	const configuration = require('./configuration')
7
	let error = null
8
	let output = null
9
10
	validate.sourceConfiguration(input, (validatedInput, thrownError) => {
11
		input = validatedInput
12
		error = thrownError
13
	})
14
15
	// Send MQTT
16
	if ( !error ) {
17
		let configurationMqtt = configuration.mqtt(input)
18
		let client = mqtt.connect(input.source.url, configurationMqtt)
19
		let version = null
20
21
		client.on('connect', () => {
22
			let topic = input.source.prefix + '/' + process.env.BUILD_TEAM_NAME + '/' + process.env.BUILD_PIPELINE_NAME
23
			console.log(topic)
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
24
			client.subscribe(topic, (errorConnection) => {
25
				if ( !errorConnection ) {
26
					client.on('message', (topic, message) => {
27
						version = message.toString()
28
						client.end()
29
					})
30
				} else {
31
					error = errorConnection
32
				}
33
			})
34
		})
35
36
		output = [
37
			{'ref': version}
38
		]
39
	}
40
41
	callback(error, output)
42
}
43